/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : MqcpDeviceInfoReport.c
  * @brief          : MqcpDeviceInfoReport
  ******************************************************************************
  * @attention
  * 本文件用于  用户信息上报
  * @20210414:文件模板第一次生成
  *
  ******************************************************************************
  */
/* USER CODE END Header */

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */


#include "MqcpDeviceInfoReport.h"

static MqcpDataDef *MqcpDeviceInfoReqProcess(MqcpMessageDef *mData);
static MqcpDataDef *MqcpDeviceInfoRespProcess(MqcpMessageDef *mData);


void DeviceInfoInit(void)//用户信息上报初始化
{
	MqcpRouterDef routeReq = 
	{
		1,
		DeviceInfoReportReq,
		MqcpDeviceInfoReqProcess
	};
	while(addRouter(routeReq));
	
	MqcpRouterDef routeResp = 
	{
		1,
		DeviceInfoReportResp,
		MqcpDeviceInfoRespProcess
	};
	while(addRouter(routeResp));
}

MqcpDataDef *MqcpDeviceInfoReqProcess(MqcpMessageDef *mData)
{
	MqcpDataDef *MqcpData = rt_malloc(sizeof(MqcpDataDef));
	
	if(NULL == MqcpData)
	{
		return NULL;
	}
	
	MqcpData->isNeedResp = 0;
	MqcpData->Size = 0;
	uint16_t MessageSize = 0;
	
	rt_memset(MqcpData->MqcpMessage.MsgId, 0, 12);MqcpData->Size = MqcpData->Size + 12;
	MqcpData->MqcpMessage.Sync = MqcpSyncFalse;MqcpData->Size = MqcpData->Size + 1;
	MqcpData->MqcpMessage.Code = MqcpCodeOK;MqcpData->Size = MqcpData->Size + 1;
	MqcpData->MqcpMessage.Ver = MQCP_USE_VER;MqcpData->Size = MqcpData->Size + 1;
	MqcpData->MqcpMessage.DevID[3] = MqcpDevice.DevId>>24;
	MqcpData->MqcpMessage.DevID[2] = MqcpDevice.DevId>>16;
	MqcpData->MqcpMessage.DevID[1] = MqcpDevice.DevId>>8;
	MqcpData->MqcpMessage.DevID[0] = MqcpDevice.DevId&0xff;MqcpData->Size = MqcpData->Size + 4;
	MqcpData->MqcpMessage.Cmd = DeviceInfoReportReq;MqcpData->Size = MqcpData->Size + 1;
	
	rt_memcpy(MqcpData->MqcpMessage.Data, MqcpNet.ICCID, 20);MqcpData->Size = MqcpData->Size + 20;MessageSize = MessageSize +20;
	MqcpData->MqcpMessage.Data[20] = MqcpNet.CSQ;MqcpData->Size = MqcpData->Size + 1;MessageSize = MessageSize +1;
	MqcpData->MqcpMessage.Data[21] = MqcpNet.Connect;MqcpData->Size = MqcpData->Size + 1;MessageSize = MessageSize +1;
	MqcpData->MqcpMessage.Len[1] = MessageSize>>8;
	MqcpData->MqcpMessage.Len[0] = MessageSize&0xff;MqcpData->Size = MqcpData->Size + 2;
	MqcpData->MqcpMessage.Data[22] = Chack_Xor((uint8_t*)(&(MqcpData->MqcpMessage)),MqcpData->Size);MqcpData->Size = MqcpData->Size + 1;
	
	return MqcpData;
}

MqcpDataDef *MqcpDeviceInfoRespProcess(MqcpMessageDef *mData)
{
	MqcpDataDef *MqcpData = rt_malloc(sizeof(MqcpDataDef));
	
	if(NULL == MqcpData)
	{
		return NULL;
	}
	
	MqcpData->isNeedResp = 0;
	MqcpData->Size = 0;
	
	return MqcpData;
}

/************************ (C) COPYRIGHT CunJu *****END OF FILE****/
